package panel.recommendPathInfo
{
	import assists.HtmlText;
	import assists.Lang;
	import assists.TextFieldUtils;
	import assists.URI;
	import assists.resource.ResourceLoader;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.text.TextField;
	
	public class PathInfoBox extends Sprite
	{
		private var _stage:Stage;
		private var _loader:ResourceLoader;
		private var _lang:Lang;
		private var _uri:URI;
		
		private var dataPic:Sprite;
		private var pathText:TextField;
		
		private var rightIcon:Sprite;
		
		private var hei1:Number = 0;
		private var hei2:Number = 0;
		
		private var _onRePo:Function;
		
		public var data:Array;
		public var titleString:String;
		
		public function PathInfoBox(stage:Stage, loader:ResourceLoader, lang:Lang, uri:URI)
		{
			_stage = stage;
			_loader = loader;
			_lang = lang;
			_uri = uri;
			
			data = [];
		}
		
		public function changeData(list:Array,num:int):void
		{
			data = list;
			
			dataPic = new Sprite;
			this.addChild(dataPic);
			dataPic.x = 0;//_stage.stageWidth * .01;
			dataPic.y = _stage.stageWidth * .01;
			
			var desc:TextField = new TextField;
			desc.mouseEnabled = true;
			desc.selectable = false;
			desc.wordWrap = false;
			desc.multiline = false;
			
			TextFieldUtils.setHtmlText(desc,HtmlText.formatSizeColor(_lang.client("第几天",{num:(num + 1)}),0x000000));
			desc.width = desc.textWidth + 4;
			desc.height = desc.textHeight + 4;
			
			var image:Bitmap = new _loader.uiManager.dateMarkBack as Bitmap;

			dataPic.addChild(image);
			dataPic.addChild(desc);	
			
			image.width = _stage.stageWidth * .3;
			image.height = _stage.stageHeight * .05;
			
			desc.x = (image.width - desc.width) / 2;
			desc.y = (image.height - desc.height) / 2;
			
			pathText = new TextField;
			pathText.mouseEnabled = true;
			pathText.selectable = false;
			pathText.multiline = true;
			pathText.wordWrap = true;
			pathText.width = _stage.stageWidth * .7;
			pathText.x = _stage.stageWidth * .05;
			pathText.y = _stage.stageHeight * .06;
			
			this.addChild(pathText);
			
			var str:String = "";
			for(var i:int = 0;i < list.length;i++){
				if(list[i]){
					str = str + "→" + list[i].name;
				}
			}
			TextFieldUtils.setHtmlText(pathText,HtmlText.formatSizeColor(str,0xFFFF00),true,true);
			pathText.height = pathText.textHeight + 4;
			
			hei2 = pathText.y + pathText.height;
			
			var img:Bitmap = new _loader.uiManager.arrowIcon as Bitmap;
			rightIcon = new Sprite;
			rightIcon.addChild(img);
			repositionImg();
		}
		
		private function repositionImg():void
		{	
			this.addChild(rightIcon);
			
			rightIcon.x = _stage.stageWidth - rightIcon.width - _stage.stageWidth * .01;
			rightIcon.y =  _stage.stageHeight * .06;
			
			
			if(_onRePo is Function){
				_onRePo();
			}
		}
		
		public override function get height():Number
		{
			return hei2;//(hei1 + hei2);
		}
		
		public function set onRepo(func:Function):void
		{
			_onRePo = func;
		}
		
		public function clear():void
		{
			if(_stage != null){
				_stage = null;
				_loader = null;
				_lang = null;
				_uri = null;
				
				dataPic = null;
				pathText = null;
				rightIcon = null;
				hei2 = 0;
			}
		}
	}
}